package osgiequinoxpluginprojectclient;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import osgiequinoxpluginproject.Hello;

public class HelloUser implements BundleActivator
{

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	@Override
	public void start(final BundleContext ctx) throws Exception
	{
		ServiceReference<?> ref = ctx.getServiceReference(Hello.class.getName());
		if (ref != null)
		{
			Hello hello = null;
			try
			{
				hello = (Hello) ctx.getService(ref);
				if (hello != null)
				{
					hello.sayHello();
				}
				else
				{
					System.out.println("Service:Hello---objectnull");
				}
			}
			catch (RuntimeException e)
			{
				e.printStackTrace();
			}
			finally
			{
				ctx.ungetService(ref);
				hello = null;
			}
		}
		else
		{
			System.out.println("Service:Hello---notexists");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	@Override
	public void stop(final BundleContext context) throws Exception
	{
	}

}
